package session;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import persistence.General;
import util.SqlConnection;

public class GeneralSession {
	
	private SqlSession session;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryTipoCanal(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();
		
		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryTipoCanal(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryTipoDirec(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();
		
		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryTipoDirec(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryTipoPers(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();
		
		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryTipoPers(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryEstadoSol(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();
		
		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryEstadoSol(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryTipoDocu(int flg){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();

		mapa.put("xFLG", flg);
		
		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryTipoDocu(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryTipoSolic(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();

		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryTipoSolic(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryBieServicio(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();

		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryBieServicio(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryDepa(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();

		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryDepa(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryPrvi(int codigoDep){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();
		
		mapa.put("xCOD_DEP", codigoDep);

		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryPrvi(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryDist(int codigoDep,int codigoPrvi){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();
		
		mapa.put("xCOD_DEP", codigoDep);
		mapa.put("xCOD_PRVI", codigoPrvi);

		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryDist(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryTipoEntidad(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();

		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryTipoEntidad(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		}finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryVia(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();

		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryVia(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		} finally{
			session.close();
		}
		return lista;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ArrayList<Object> queryCodigoIntdir(){
		Map mapa = new HashMap<String, Object>();
		ArrayList<Object> lista = new ArrayList<Object>();

		try {
			session = SqlConnection.getSessionFactory().openSession();
			General general = session.getMapper(General.class);
			
				general.queryCodigoIntDir(mapa);
				lista = (ArrayList<Object>) mapa.get("ocursor");

		} catch (Exception e) {
			System.out.println(e);
		} finally{
			session.close();
		}
		return lista;
	}
	
}
